/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;

import DAO.DriversDAO;
import DAO.RequestDAO;
import Models.Company;
import Models.Drivers;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author phuong
 */
@ManagedBean
@RequestScoped
public class RequestController {      
    /** Creates a new instance of RequestController */

    List<Drivers> listDr = new ArrayList<Drivers>();
    
    public List<Drivers> getListDr() throws Exception {
        return listDr=RequestDAO.requestFromDriver();
    }

    public void setList(List<Drivers> list) {
        this.listDr = list;
    }
    
    public void updateAcceptDr(int id) throws Exception{RequestDAO.updateAcceptDriver(id);}
    public void updateDenyDr(int id) throws Exception{RequestDAO.updateDenyDriver(id);}
    //public void deleteDriver(int id) throws Exception {RequestDAO.deleteDriver(id);}
//    public void updateEditDriver(String name, String contactPerson, String address, String city, String mobile, String telephone, String experience, String description, int id) throws Exception
//    {
//        DriversDAO.editDriver(name, contactPerson, address, city, mobile, telephone, experience, description, id);
//    }
     public void editSubmit() throws Exception{
    Drivers dr = (Drivers) (FacesContext.getCurrentInstance().getExternalContext().
                getRequestMap().get("driverBean"));
        DriversDAO.editDriver(dr);
    }
    
    //-------------------------
    
    List<Company> listCom = new ArrayList<Company>();
    
    public List<Company> getListCom() throws Exception {
        return listCom=RequestDAO.requestFromList();
    }

    public void setListing(List<Company> list) {
        this.listCom = list;
    }
    
    public void updateAcceptLt(int id) throws Exception{RequestDAO.updateAcceptList(id);}
    public void updateDenyLt(int id) throws Exception{RequestDAO.updateDenyList(id);}
    
    
    
     public void selectedID(int selectedID) {
        ExternalContext e = FacesContext.getCurrentInstance().getExternalContext();
        HttpSession session = (HttpSession) e.getSession(true);
        session.setAttribute("selectedID", selectedID);
    }
    
    public void deleteDriver() throws Exception {
        ExternalContext e = FacesContext.getCurrentInstance().getExternalContext();
        HttpSession session = (HttpSession) e.getSession(true);
        int id = Integer.parseInt(session.getAttribute("selectedID").toString());
        DriversDAO.deleteDriver(id);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Information: ", "Driver has been deleted !"));
    }
    public RequestController() {
    }
}
